<template>

	<view class="search-wrap" @click="onClick">
		<view class="search-wrap-box">
			<image class="search-icon" src="https://cdn.quantifynet.cn/dti/search_gray@2x.png"></image>
			<input class="search-info" placeholder-style="color:#999999" :disabled="disabled" :focus="showSync"
				:placeholder="placeholder" :maxlength="maxlength" @confirm="confirm" confirm-type="search" type="text"
				v-model="searchVal"></input>
		</view>
	</view>



</template>

<script>
	export default {
		name: 'USearch',
		props: {
			disabled: {
				type: Boolean,
				default: true
			},
			placeholder: {
				type: String,
				default: '请输入搜索内容'
			},
			maxlength: {
				type: [Number, String],
				default: 100
			},
			keyword: {
				type: String,
				default: ''
			},
			showSync: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				// showSync: false,
				searchVal: ''
			};
		},
		watch: {
			searchVal() {
				this.$emit('input', {
					value: this.searchVal
				});
			},
			keyword: {
				handler(val) {
					// console.log(val);
					this.keyword = val;
					// console.log(this.keyword)
					this.searchVal = this.$props.keyword;
				},
				immediate: true
			}
		},
		methods: {
			searchClick() {
				this.searchVal = '';
				this.$nextTick(() => {
					this.showSync = true;
				});
			},
			clear() {
				this.searchVal = '';
			},
			cancel() {
				this.$emit('cancel', {
					value: this.searchVal
				});
				this.searchVal = '';
				this.showSync = false;
			},
			confirm() {
				this.$emit('confirm', {
					value: this.searchVal
				});
			},
			onClick() {
				this.$emit('click');
			}
		}
	};
</script>

<style lang="less" scoped>
	.search-wrap {
		// max-width: 686rpx;
		height: 70rpx;
		border-radius: 35rpx;
		background-color: rgba(255, 255, 255, 1);
		box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
		align-self: center;
		margin-top: 20rpx;
		// width: 686rpx;
		justify-content: center;
		align-items: flex-start;
		padding-left: 34rpx;
		display: flex;
		flex-direction: column;

		.search-wrap-box {
			width: 100%;
			// width: 333rpx;
			height: 70rpx;
			line-height: 70rpx;
			flex-direction: row;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.search-icon {

				width: 34rpx;
				height: 34rpx;
			}

			.search-info {
				// width: 276rpx;
				width: 100%;
				display: block;
				overflow-wrap: break-word;
				color: rgba(153, 153, 153, 1);
				font-size: 24rpx;
				font-family: PingFangSC-Regular;
				white-space: nowrap;
				// line-height: 33rpx;
				text-align: left;
				padding: 0 23rpx;
				box-sizing: border-box;
					
			}


			input::placeholder {
				font-size: 24px;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #999999;

			}


		}


	}
</style>
